package com.baize.minespace.controller;


import com.baize.minespace.pojo.Comments;
import com.baize.minespace.service.CommentsService;
import com.baize.minespace.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 评论信息表 前端控制器
 * </p>
 *
 * @author baize
 * @since 2024-04-15
 */
@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

    @ApiModelProperty("新增评论信息表")
    @ApiOperation(value = "新增评论信息表", notes = "新增评论信息表")
    @PostMapping("add")
    public Result<Boolean> addComments(@RequestBody Comments comments){
        return Result.success(commentsService.save(comments));
    }

    @ApiModelProperty("删除评论信息表")
    @ApiOperation(value = "删除评论信息表", notes = "删除评论信息表")
    @GetMapping ("delete/{id}")
    public Result<Boolean> deleteComments(@PathVariable(value = "id") Integer id) {
        return Result.success(commentsService.removeById(id));
    }

    @ApiModelProperty("修改评论信息表")
    @ApiOperation(value = "修改评论信息表", notes = "修改评论信息表")
    @PostMapping("update")
    public Result<Boolean> updateComments(@RequestBody Comments comments) {
        return Result.success(commentsService.updateById(comments));
    }

    @ApiModelProperty("查询评论信息表")
    @GetMapping("select/{id}")
    public Result<Comments> selectComments(@PathVariable(value = "id") Integer id) {
        return Result.success(commentsService.getById(id));
    }

    @ApiModelProperty("分页查询评论信息表")
    @ApiOperation(value = "分页查询评论信息表", notes = "分页查询评论信息表")
    @GetMapping("page/{rows}/{page}")
    public Result<IPage<Comments>> selectCommentsPage(
        @PathVariable(value = "rows") Integer rows,
        @PathVariable(value = "page") Integer page,
        @RequestBody Comments comments
    ) {
        return commentsService.selectCommentsPage(rows, page, comments);
    }
}
